import Vue from 'vue'
import VueRouter from 'vue-router'
import BoyView from '../views/BoyView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/boy'
  },
  {
    path:'/boy',
    name:"boy",
    component:BoyView
  },
  {
    path:'/girl',
    name:"girl",
    component: () => import("../views/GirlView.vue")
  },
  {
    path:'/login',
    name:"login",
    component: () => import("../views/LoginView.vue")
  },
  {
    path:'/page1',
    name:"page1",
    component: () => import("../views/Page_jumpView.vue")
  },
  {
    path:'/page2',
    name:"page_two",
    component: () => import("../views/Page_jump_twoView.vue")
  },
  {
    path:'/page3',
    name:"page_three",
    component: () => import("../views/Page_jump_threeView.vue")
  },
  {
    path:'/page4',
    name:"page_four",
    component: () => import("../views/Page_jump_fourView.vue")
  },
  {
    path:'/page5',
    name:"page_five",
    component: () => import("../views/Page_jump_fiveView.vue")
  },
  {
    path:'/details',
    name:"details",
    component: () => import("../views/book_detailsView.vue")
  },
  {
    path:'/catalogue',
    name:"catalogue",
    component: () => import("../views/catalogueView.vue")
  },
  {
    path:'/bookmark',
    name:"bookmark",
    component: () => import("../views/bookmarkView.vue")
  },
  {
    path:'/read',
    name:"read",
    component: () => import("../views/readView.vue")
  },
  {
    path:'/search',
    name:"search",
    component: () => import("../views/searchView.vue")
  },
  {
    path:'/search_details',
    name:"search_details",
    component: () => import("../views/search_detailsView.vue")
  },
  {
    path:'/monthly',
    name:"monthly",
    component: () => import("../views/monthly_ticketView.vue")
  },
  {
    path:'/recommend',
    name:"recommend",
    component: () => import("../views/recommend_ticketView.vue")
  },
  {
    path:'/currency',
    name:"currency",
    component: () => import("../views/currencyView.vue")
  },
  {
    path:'/recharge',
    name:"recharge",
    component: () => import("../views/recharge_View.vue")
  },
  {
    path:'/recharge_Alipay',
    name:"recharge_Alipay",
    component: () => import("../views/recharge_AlipayView.vue")
  },
  {
    path:'/info',
    name:"info",
    component: () => import("../views/infoView.vue")
  },
  {
    path:'/member',
    name:"member",
    component: () => import("../views/memberView.vue")
  },
  {
    path:'/grade',
    name:"grade",
    component: () => import("../views/gradeView.vue")
  },
  {
    path:'/security',
    name:"security",
    component: () => import("../views/securityView.vue")
  },
  {
    path:'/help',
    name:"help",
    component: () => import("../views/helpView.vue")
  },
  {
    path: '/userinfo',
    name: 'userinfo',
    component: () => import('../views/userinfoView.vue'),
    // 独享路由守卫
    beforeEnter:(to,from,next)=>{
      let token = window.localStorage.getItem("token");
      // 判断是否登录
      if(!token){
        next("/login");
        return;
      }else{
        next();
      }
    }
  },
  {
    path: '/bookshifon',
    name: 'bookshifon',
    component: () => import('../views/BookShelfNoView.vue'),
  },
  {
    path:'/bookshif',
    name:"bookshif",
    component: () => import("../views/BookShifView.vue"),
    // 独享路由守卫
    beforeEnter:(to,from,next)=>{
      let token = window.localStorage.getItem("token");
      // 判断是否登录
      if(!token){
        next("/bookshifon");
        return;
      }else{
        next();
      }
    }
  },
]


// 注意:解决路由跳转问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location){
  return originalPush.call(this,location).catch(err=>err);
}


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior () {
    return { x: 0, y: 0 }
  }
})

export default router
